import java.util.*; public class HelloWorld{ public static void test(final List<Integer> ints) { ints.add(5); } public static void main(final String[] arguments) { final List<Integer> ints = new ArrayList<>(); test(ints); System.out.println(ints.size()); } }
public class HelloWorld{ public static void main(String []args){ double u, i, r; i = 10; // ток Ампер r = 200; // сопротивление Ом u = i*r; // формула нахождения напряжения на конце проводника Вольт System.out.println("Напряжение = " + (u) + " Вольт"); } }
import java.util.Random; class WeatherReport { private int temperature; private int windSpeed; private String windDirection; private static int weatherReportStationNumber = 0; public WeatherReport(int temperature, int windSpeed, String windDirection){ this.temperature = temperature; this.windSpeed = windSpeed; this.windDirection = windDirection; } public void setTemperature(int temperature) { this.temperature = temperature; } public int getTemperature() { return temperature; } public void setWindSpeed(int windSpeed){ this.windSpeed = windSpeed; } public int getWindSpeed(){ return windSpeed; } public void setWindDirection() { Random x = new Random(); int check = x.nextInt(4); switch(check){ case 0: this.windDirection = "NORTH"; break; case 1: this.windDirection = "EAST"; break; case 2: this.windDirection = "WEST"; break; case 3: this.windDirection = "SOUTH"; break; } } public String getWindDirection() { return windDirection; } public String methodOne(int temperature, int windSpeed, String windDirection){ String dressCode = ""; int product = temperature + windSpeed; if(windDirection == "NORTH" && temperature <= -20){ if(temperature< -20){ dressCode = "stay inside"; } } else { if(product<=0) dressCode = "winter coat"; else if(product<=15) dressCode = "light coat"; else if(product>15) dressCode = "shorts"; } return dressCode; } public static void randomWeatherReportStationVariable(){ Random x = new Random(); int assignment = x.nextInt(51) + 100; weatherReportStationNumber = assignment; System.out.println(assignment); } public String methodTwo(String name) { String interleavedString = ""; if(name.length() == windDirection.length()) { for(int x = 0; x<name.length();x++){ interleavedString += name.charAt(x); interleavedString += windDirection.charAt(x); } } else{ interleavedString = "ERROR"; } return interleavedString; } public int methodThree(int factor){ int windFactor = 0; windFactor = windSpeed/factor; return windFactor; } } public class WeatherReportTestHarness{ public static void main(String []args){ WeatherReport[][] testArray = new WeatherReport[7][3]; //randomWeatherReportStationVariable(); int z = 0; for(int x = 0;x<3;x++){ for(int i = 0;i<7;i++){ z += 2; testArray[i][x] = new WeatherReport((-24 + z), (0 + z), ""); testArray[i][x].setWindDirection(); } } for(int x = 0;x<3;x++){ for(int i = 0;i<7;i++){ System.out.println("Temperature at index " + i + x + " is " + testArray[i][x].getTemperature()); System.out.println("----------------------------------"); System.out.println("Wind Speed at index " + i + x + " is " + testArray[i][x].getWindSpeed()); System.out.println("----------------------------------"); System.out.println("Wind Direction at index " + i + x + " is " + testArray[i][x].getWindDirection()); System.out.println("----------------------------------"); System.out.println("Dress Code at index " + i + x + " is " + testArray[i][x].methodOne(testArray[i][x].getTemperature(), testArray[i][x].getWindSpeed(), testArray[i][x].getWindDirection())); //System.out.println("----------------------------------"); //System.out.println("The Weather Report Station Number is " + weatherReportStationNumber); System.out.println("----------------------------------"); System.out.println(testArray[i][x].methodTwo("HELLO")); System.out.println("----------------------------------"); if(testArray[i][x].getWindDirection().contains("TH") == true){ System.out.println("index " + i + x + "contains th"); System.out.println("Temperature at index " + i + x + " is " + testArray[i][x].getTemperature()); System.out.println("----------------------------------"); System.out.println("Wind Speed at index " + i + x + " is " + testArray[i][x].getWindSpeed()); System.out.println("----------------------------------"); System.out.println("Wind Direction at index " + i + x + " is " + testArray[i][x].getWindDirection()); System.out.println("----------------------------------"); } } } } }
import java.util.regex.*; public class PatternMatch { public static void main(String args[]) { int count=0; //Pattern p=Pattern.compile("\\s"); //Pattern p=Pattern.compile("o"); // Pattern p=Pattern.compile("\\."); Pattern p=Pattern.compile("[.]"); // String s[]=p.split("Infosys Software Solution"); String s[]=p.split("WWW.Infosys.COM"); for(String s1:s) { System.out.println(s1); } } }
import java.util.regex.*; public class Main { public static boolean isValid(String s) { Pattern p=Pattern.compile("(0|\\+91[\\s])?[7-9][0-9]{9}"); Matcher m=p.matcher(s); return (m.find() && m.group().equals(s)); } public static void main(String args[]) { String str="+91 9415074505"; if(isValid(str)) { System.out.println("It is a valid mobile number"); } else { System.out.println("It is invalid mobile number"); } } }
import java.util.regex.*; //import java.util.Scanner; public class PatternMatch { public static void main(String args[]) { // Scanner sc=new Scanner(System.in); // System.out.println("Enter the Pattern String"); // String ptr=sc.nextLine(); // System.out.println("Enter the Target String"); // String tar=sc.nextLine(); int count=0; //Pattern p=Pattern.compile("[ab]"); // Pattern p=Pattern.compile("[^ab]"); // Pattern p=Pattern.compile("[a-z]"); // Pattern p=Pattern.compile("[^a-z]"); // Pattern p=Pattern.compile("[A-Z]"); // Pattern p=Pattern.compile("[a-zA-Z0-9]"); Pattern p=Pattern.compile("[^a-zA-Z0-9]"); Matcher m=p.matcher("a7b@z#9"); while(m.find()) { count++; //int endData=m.end(); // endData-=1; System.out.println(m.start()+"....."+m.group()); } System.out.println("The total number of occurences is "+count); } }
//(c) A+ Computer Science //www.apluscompsci.com //Name - Bryan Nieto import static java.lang.System.*; public class CardRunner { public static void main( String args[] ) { Card one = new Card("SPADES", 9); out.println(one.getSuit()); out.println(one.getFace()); Card two = new Card("DIAMONDS", 1); out.println(two); two.setFace(3); out.println(two); Card three = new Card("CLUBS", 4); out.println(three); Card four = new BlackJackCard("SPADES", 1); out.println(four); Card five = new BlackJackCard("HEARTS", 13); out.println(five); Card six = new BlackJackCard("HEARTS", 11); out.println(six); Card seven = new BlackJackCard("CLUBS", 12); out.println(seven); } } class Card { public static final String FACES[] = {"ZERO","ACE","TWO","THREE","FOUR", "FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING"}; //instance variables private String suit; private int face; //constructors public Card( String s, int f) { suit = s; face = f; } // modifiers public void setFace( int f) { face = f; } public void setSuit( String s) { suit = s; } //accessors public String getSuit() { return suit; } public int getFace() { return face; } //toString public String toString() { return FACES[face] + " of " + suit; } } class BlackJackCard extends Card //Card is superclass { //Create a constructor that recieves a suit and a face public BlackJackCard(String s,int f) { super(s, f ); //'super' refers to the Card superclass } //make a getValue() method that returns the worth of the card //based on the rules of BLackJack public int getValue() { //create if statements for the conditions below //Ace is worth 11 for now if( getFace() == 1) return 11; //Jack, Queen, and King are all worth 10 if( getFace() > 10) return 10; // all other cards are face value else return getFace(); } //make a toString method public String toString() { //return output example in lab return super.toString() + " " + getValue(); } }
//(c) A+ Computer Science //www.apluscompsci.com //Name - Zeanna Jeffries import static java.lang.System.*; import java.awt.Color; public class CardRunner { public static void main( String args[] ) { Card one = new Card("SPADES", 9); out.println(one.getSuit()); out.println(one.getFace()); Card two = new Card("DIAMONDS", 1); out.println(two); two.setFace(3); out.println(two); Card three = new Card("CLUBS", 4); out.println(three); Card four = new Card("SPADES", 1); out.println(four); Card five = new Card("HEARTS", 13); out.println(five); Card six = new Card("HEARTS", 11); out.println(six); Card seven = new Card("CLUBS", 12); out.println(seven); } } class Card { public static final String FACES[] = {"ZERO","ACE","TWO","THREE","FOUR", "FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING"}; //instance variables private String suit; private int face; //constructors public Card( String s, int f) { suit = s; face = f; } // modifiers public void setFace( int f) { face = f; } public void setSuit( String s) { suit = s; } //accessors public String getSuit() { return suit; } public int getFace() { return face; } //toString public String toString() { return FACES[face] + " of " + suit; } } class BlackJackCard extends Card { public BlackJackCard(String s, int f) { super(s, f); } public int getValue() { if (getFace()==1) return 11; if (getFace()>10) return 10; else return getFace(); } public String toString() { return super.toString() + " " + getValue(); } }
import java.util.Scanner; public class ChkPalindrome { public static void main(String args[]) { String str, rev = ""; Scanner sc = new Scanner(System.in); System.out.println("Enter a string:"); str = sc.nextLine(); int length = str.length(); for ( int i = length - 1; i >= 0; i-- ) rev = rev + str.charAt(i); if (str.equals(rev)) System.out.println(str+" is a palindrome"); else System.out.println(str+" is not a palindrome"); } }
import java.util.*; public class Sok{ //static Scanner sc=new Scanner(System.in); public static void main(String []args){ int [] lista ={6,3,8,1,5}; int index= -1; int varde=3; System.out.println("talet finns i listan"+ index); for(int i = 0; i<lista.length;i++){ if(lista[i] == varde) { index = i; break; } } //return index; } } //bubbelsortering /*public static void bubbleSort(double data[]) { for(int m = data.length-1; m > 0; m--) { for(int n = 0; n < m; n++) { if(data[n] > data[n+1]) { double temp = data[n]; data[n] = data[n+1]; data[n+1] = temp; } } } } //https://www.youtube.com/watch?v=RqfWvIsYmsc }*/
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more