User:Binari: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 116:
System.out.println("Take one down and pass it around, "+(i-1)+" bottles of beer on the wall.");
System.out.println(); //no grammar
}
}/* package whatever; // don't place package name! */
{}
}
</lang>
 
==HTTP==
<lang java>
import java.ionet.*;
import java.io.*;
 
class IdeoneHTTP {
public static void main (String[] args) throws java.lang.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); //no grammar
}
in.close();
}
}
</lang>
 
==String matching==
<lang java>
import java.util.*;
import java.lang.*;
import java.io.*;
 
class matching {
/* Name of the class has to be "Main" only if the class is public. */
public static void main(String[] args) {
class Ideone
String s1,s2;
{
String t1="no",t2="no",t3="no";
public static void main (String[] args) throws java.lang.Exception
Scanner iste=new Scanner(System.in);
{
System.out.print("First string: ");
for (int i=99; i>=1; i--) {
s1=iste.next();
System.out.println(i+" bottles of beer on the wall, "+i+" bottles of beer");
System.out.print("Second string: ");
System.out.println("Take one down and pass it around, "+(i-1)+" bottles of beer on the wall.");
s2=iste.next();
System.out.println(); //no grammar
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=990; i>=1<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