User:Binari: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 72:
}
// your code goes here
}
}
</lang>
 
==Loops/N plus one half==
<lang java>
/* package whatever; // don't place package name! */
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
for (int i=1; i<=10; i++) {
System.out.print(i);
if (i!=10) System.out.print(", ");
else System.out.println();
}
// your code goes here
}
}
</lang>
 
==99 Bottles of Beer==
<lang java>
/* package whatever; // don't place package name! */
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
for (int i=99; i>=1; i--) {
System.out.println(i+" bottles of beer on the wall, "+i+" bottles of beer");
System.out.println("Take one down and pass it around, "+(i-1)+" bottles of beer on the wall.");
System.out.println(); //no grammar
}
}
}
</lang>
 
==HTTP==
<lang java>
import java.net.*;
import java.io.*;
 
class HTTP {
public static void main(String[] args) throws Exception {
URL url=new URL("http://emreperde.com");
BufferedReader in= new BufferedReader(new InputStreamReader(url.openStream()));
String oku;
while ((oku=in.readLine())!=null) {
System.out.println(oku);
}
in.close();
}
}
</lang>
 
==String matching==
<lang java>
import java.util.*;
import java.lang.*;
 
class matching {
public static void main(String[] args) {
String s1,s2;
String t1="no",t2="no",t3="no";
Scanner iste=new Scanner(System.in);
System.out.print("First string: ");
s1=iste.next();
System.out.print("Second string: ");
s2=iste.next();
if (s1.startsWith(s2)) { t1="yes"; t3="yes"; }
if (s1.endsWith(s2)) { t2="yes"; t3="yes"; }
if (s1.indexOf(s2)!=-1) t3="yes";
System.out.println("First string:");
System.out.println("starts with second string? "+t1);
System.out.println("contains the second string at any location? "+t3);
System.out.println("ends with second string? "+t2);
}
}
</lang>
 
==Roman numerals/Decode==
<lang java>
import java.util.*;
import java.lang.*;
 
class romaDecode {
public static void main(String[] args) {
int say=0;
Scanner iste=new Scanner(System.in);
System.out.print("Enter Roman numeral: ");
String yaz=iste.next();
for (int i=0; i<yaz.length(); i++) {
switch(yaz.charAt(i)) {
case 'M': say+=1000; break;
case 'L': say+=50; break;
case 'X':
if (i!=yaz.length()-1) {
if (yaz.charAt(i+1)=='L' || yaz.charAt(i+1)=='C') say-=10;
else say+=10; }
else say+=10;
break;
case 'I':
if (i!=yaz.length()-1) {
if (yaz.charAt(i+1)=='X' || yaz.charAt(i+1)=='V') say--;
else say++; }
else say++;
break;
case 'V': say+=5; break;
case 'C':
if (i!=yaz.length()-1) {
if (yaz.charAt(i+1)=='M') say-=100;
else say+=100; }
else say+=100;
break;
case 'D': say+=500; break;
default: say=0; break;
}
}
System.out.println("Result: "+say);
}
}
Anonymous user