tag:blogger.com,1999:blog-694855878384792308.post5617095847543648930..comments2024-03-21T06:26:49.387-07:00Comments on Java67: 10 Programming questions and exercises for Java Programmersjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger58125tag:blogger.com,1999:blog-694855878384792308.post-4495885459055992622023-12-16T09:57:00.587-08:002023-12-16T09:57:00.587-08:00bro i did not understand your question properly ca...bro i did not understand your question properly can you write this again plss, it looks like interesting question....<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-63720892408752975732022-05-16T21:28:08.768-07:002022-05-16T21:28:08.768-07:00Hello Thiru, what is predefs? never heard about it...Hello Thiru, what is predefs? never heard about it?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-68402849196946206112022-05-16T09:40:31.274-07:002022-05-16T09:40:31.274-07:00i have a doubt! Is there any way of iterating thro...i have a doubt! Is there any way of iterating through strings in java without using predefs??<br />Thiruhttps://www.blogger.com/profile/13649547698764575802noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-8341492333603625792021-03-18T02:38:11.918-07:002021-03-18T02:38:11.918-07:00Write a program that reads in from the user an int...Write a program that reads in from the user an integer (num) between 1000 and 9999. Then it prompts<br />the user to enter an integer (d) between 0 and 9 and a character (ch). Your program should replace the<br />second and the last digit in num with d and it should display the character that precedes (ch) followed by<br />the number after the change and then the character that comes after (ch). Use the division and modulus<br />operators to extract the digits from num.Mo Dilshadhttps://www.blogger.com/profile/07874179523227530120noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-43430256046314288382021-02-03T20:23:21.022-08:002021-02-03T20:23:21.022-08:00WAP to accept two numbers and find the average OF ...WAP to accept two numbers and find the average OF THE AVERAGES OF THEIR DIGITSAnonymoushttps://www.blogger.com/profile/16600300566524486634noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-84068046977711313402020-09-02T07:51:53.217-07:002020-09-02T07:51:53.217-07:00Write switch case program to show given date(dd/mm...Write switch case program to show given date(dd/mm/yy) in words format.<br /><br />import java.util.Scanner;<br /><br />class Date{<br /> public static void main(String[] args) {<br /> <br /> String dow;<br /> String wowby;<br /> String yowby;<br /> <br /> Double n1,n2,res;<br /> Scanner scan = new Scanner (System.in);<br /> System.out.print("Enter Date (dd/mm/yy): ");<br /> <br /> String date = scan.nextLine();<br /> String dd = date.substring(0,2);<br /> String mm = date.substring(3,5);<br /> String yy = date.substring(6,8);<br /> <br /> int d = Integer.valueOf(dd);<br /> int m = Integer.valueOf(mm);<br /> int y = Integer.valueOf(yy);<br /> <br /> boolean valid = ((d>=1) && (d<31));<br /> //||((m>=1) && (m<12));//||((y>=00) && (y<99));<br /> <br /> if(!valid)<br /> System.out.print("Invalid date");<br /> <br /> else {<br /> switch (dd)<br /> { <br /> case "01": <br /> System.out.print("First of ");<br /> switch (mm) {<br /> case "01":<br /> System.out.print("January,2020");<br /> break;<br />Anonymoushttps://www.blogger.com/profile/07276577695463905815noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-18392696239228690022020-03-09T15:33:16.722-07:002020-03-09T15:33:16.722-07:00just a question, you cant put more than 8 digits a...just a question, you cant put more than 8 digits as the largest no. of digits for double (largest data type according to my knowledge, being only a 10th grade novice) right?<br />Anonymoushttps://www.blogger.com/profile/02212043723586900719noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-54354512078594943332019-04-21T18:49:17.447-07:002019-04-21T18:49:17.447-07:00aaaaa
bbbbb
AAAAA
BBBBB
CAN ANY ONE HELP METaaaaa<br />bbbbb<br />AAAAA<br />BBBBB <br /><br />CAN ANY ONE HELP METAnonymoushttps://www.blogger.com/profile/08474471279410591687noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-85732306010152893172018-01-18T21:47:45.147-08:002018-01-18T21:47:45.147-08:00Hi! I need help please. I need the code for this e...Hi! I need help please. I need the code for this exercise please.<br /><br /><br />At a certain store they sell blank CD's with the following discounts:<br /> <br />* 10% for 120 or more<br />* 5% for 50 or more<br />* 1% for 15 or more<br />* no discount for 14 or less<br /> <br />Write a program that asks for a number of discs bought and outputs the correct discount.Anonymoushttps://www.blogger.com/profile/01016452865679812750noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-42822831607313991722017-09-23T22:41:33.119-07:002017-09-23T22:41:33.119-07:00yes why not dude. please contact me via mustafaaft...yes why not dude. please contact me via mustafaaftab2624@gmail.comAftab Mustafa Qureshihttps://www.blogger.com/profile/05122201430780894708noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-5405088784436085872017-09-12T03:53:47.061-07:002017-09-12T03:53:47.061-07:00Hi, Sorry for the delay. I have added sample basis...Hi, Sorry for the delay. I have added sample basis of two questions in the below program. <br /><br />import java.util.*;<br />public class JavaOnlineTest {<br /> <br /> public static String questions(){<br /> Scanner sc=new Scanner(System.in);<br /> int output=0;<br /> System.out.println("1)Who is the 45th president of USA?");<br /> System.out.println("1.Barrack Obama 2.Hillary Clinton 3.Donald Trump 4.George W Bush");<br /> int answer=sc.nextInt();<br /> if(answer==3)<br /> output+=1;<br /> else<br /> output+=0;<br /> System.out.println("2)Who is the 1st Prime Minister of India?");<br /> System.out.println("1.Subash Chandra Bose 2.Jawahar Lal Nehru 3.Sardar Vallabhai Patel 4.Mahatma Gandhi");<br /> answer=sc.nextInt();<br /> if(answer==2)<br /> output+=1;<br /> else<br /> output+=0;<br /> //proceed for 3rd question here.<br /> System.out.println("Your result out of 10 is "+output);<br /> if(output>=0&&output<5){<br /> System.out.println("You've Failed");<br /> }else if(output>4 && output<8){<br /> System.out.println("Your in B Class");<br /> }else if(output>7 && output<=10){<br /> System.out.println("Your in A Class");<br /> }<br /> System.out.println("Do you want to retake the test");<br /> System.out.println("Type 'Y' or 'N'");<br /> String retaking=sc.next().trim();<br /> return retaking;<br /> }<br /><br /> public static void main(String [] args){<br /> <br /> boolean retake;<br /> <br /> String retaking;<br /> <br /> <br /> while(true){<br /> retaking=questions();<br /> if(retaking.equalsIgnoreCase("Y")){<br /> retake=true;<br /> <br /> <br /> }else if(retaking.equalsIgnoreCase("N")){<br /> System.out.println("Good Luck!...");<br /> retake=false;<br /> retaking="N";<br /> break;<br /> <br /> }<br /> }<br /> <br /> <br /> }<br />}<br />Umapathihttps://www.blogger.com/profile/17777708564808987316noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-55398175718434986752017-09-08T23:51:51.536-07:002017-09-08T23:51:51.536-07:00Good questions, can you also post answer, that wou...Good questions, can you also post answer, that would be very useful for other readers?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-66158358571398379942017-08-24T21:42:58.640-07:002017-08-24T21:42:58.640-07:00A good one is given the length of a your output me...A good one is given the length of a your output media (how wide your paper or screen is) print Pascal's Triangle in Triangle form. Stop when the next line of output will exceed your media width. You can do it two ways ... 1 is figure out how how to space the numbers so they all take the same amount of space (the "center" of the numbers are spaced the same from line to line and from each other; this makes a nice looking triangle, but is harder). 2 an easier version is to center the triangle on the page (left to right) but in each line of numbers the number are separated from each other by only one space You can get more lines in the triangle, but the "sides" are not straight and the relationship between elements gets skewed; however this is much easier. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-83673788346319373162017-08-22T18:40:57.841-07:002017-08-22T18:40:57.841-07:00Solve this plss.. fLOW CHART thta accetps a number...Solve this plss.. fLOW CHART thta accetps a number in kilowatts then display its equivalent number in.Hint:1watt=0.0001 Kilowatt. solve this in java programming<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-64444605657320781912017-08-17T16:37:45.035-07:002017-08-17T16:37:45.035-07:00Sir can you solve this problem? :
Write a java mu...Sir can you solve this problem? :<br /><br />Write a java multiple choice examination program. with 10 questions only (need a specific question). Let the user choose answer and at the end of the program output the total points to the user, output also the number of correct and wrong answer an:<br /><br />if the user got 8-10 say "Your in A class"<br />f the user got 5-7 say "Your in B class"<br />f the user got 0-4 say "Your Fail"<br /><br /><br />Note: 1. always ask the user if she/he wants to repeat the exam.<br /> 2. if yes = repeat the exam<br /> 3. if no = exit from the program.<br /><br />AnonymousRayhttps://www.blogger.com/profile/12328727210669029478noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-32833051686122162222017-06-18T23:29:29.444-07:002017-06-18T23:29:29.444-07:00try below code...
for(int row=0; row<table.leng...try below code...<br />for(int row=0; row<table.length; row++) {<br /> System.out.print(row+" ");<br /> <br /> for(int col=1; col<table[row].length; col++){<br /> if(row!=0)<br /> System.out.print(row*col+" ");<br /> else<br /> System.out.print(col+" ");<br /> <br /><br /> }<br /> System.out.println();<br /> }Umapathihttps://www.blogger.com/profile/17777708564808987316noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-10705061750360501882017-06-15T10:35:08.009-07:002017-06-15T10:35:08.009-07:00public class Pattern {
public static void main(St...public class Pattern {<br /> public static void main(String args[]){<br /> int[][] table = new int[4][4];<br /><br /><br /> for(int row=0; row<table.length; row++) {<br /> for(int col=0; col<table[row].length; col++){<br /> System.out.print(" "+row*col+" ");<br /><br /> }<br /> System.out.println();<br /> }<br /><br /> }<br /><br /><br />}<br /><br />output:<br /> 0 0 0 0 <br /> 0 1 2 3 <br /> 0 2 4 6 <br /> 0 3 6 9 <br /><br />Output needed is:<br /><br /> 0 1 2 3 <br /> 1 1 2 3 <br /> 2 2 4 6 <br /> 3 3 6 9 <br /><br /><br />what did i do wrong?Anonymoushttps://www.blogger.com/profile/00797976155355103648noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-11778163392916654932017-06-06T23:16:27.436-07:002017-06-06T23:16:27.436-07:00yes you are right.yes you are right.Umapathihttps://www.blogger.com/profile/17777708564808987316noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-40534578737169098632017-06-06T08:22:21.403-07:002017-06-06T08:22:21.403-07:00Solution:
import java.io.BufferedReader;
import j...Solution:<br /><br />import java.io.BufferedReader;<br />import java.io.IOException;<br />import java.io.InputStreamReader;<br />import java.util.Arrays;<br /><br />public class vowelCount {<br /><br /> public static void main (String [] args) throws IOException{<br /> <br /> BufferedReader b=new BufferedReader (new InputStreamReader(System.in));<br /> System.out.println("Enter a line");<br /> String line=b.readLine();<br /> String[] solution = line.split("(?!^)");<br /> System.out.println("Word is :" +line);<br /> System.out.println("Vowels are :");<br /> for (String s :solution)<br /> {<br /> char c= s.charAt(0);<br /> switch(c){<br /> <br /> case 'a':<br /> case 'e':<br /> case 'i':<br /> case 'o':<br /> case 'u':<br /> System.out.println(c);<br /> break;<br /> default:<br /> <br /> }<br /> }<br /> <br /> }<br />}<br />abhishekhttps://www.blogger.com/profile/15405653497868910661noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-63764010138066108712017-06-06T08:05:25.137-07:002017-06-06T08:05:25.137-07:00Answer:
import java.io.BufferedReader;
import jav...Answer:<br /><br />import java.io.BufferedReader;<br />import java.io.IOException;<br />import java.io.InputStreamReader;<br />import java.util.Arrays;<br /><br />class Solution{<br /> <br /> public int[] strArrayToIntArray(String[] a){<br /> int[] b = new int[a.length];<br /> for (int i = 0; i < a.length; i++) {<br /> b[i] = Integer.parseInt(a[i]);<br /> }<br /><br /> return b;<br /> }<br /> <br /> public int nextPrime(int num) {<br /> num++;<br /> for (int i = 2; i <num; i++) {<br /> if(num%i == 0) {<br /> num++;<br /> i=2;<br /> } else{<br /> continue;<br /> }<br /> }<br /> return num;<br /> }<br /><br /> public int[] nextPrime(int[] data) {<br /> <br /> for (int i=0;i<data.length;i++){<br /> <br /> data[i]=nextPrime(data[i]);<br /> <br /> <br /> }<br /> return data;<br /> }<br />}<br />public class NextPrime {<br /> <br /> public static void main (String[] args) throws IOException{<br /> <br /> System.out.println("Enter the numbers Separated space ");<br /> BufferedReader br = new BufferedReader (new InputStreamReader(System.in));<br /> String s =br.readLine();<br /> String [] question = s.split(" ");<br /> Solution sol = new Solution();<br /> int[] data = sol.strArrayToIntArray(question);<br /> int [] result = sol.nextPrime(data);<br /> System.out.println("Result is :"+Arrays.toString(result));<br /> }<br /><br />}<br />abhishekhttps://www.blogger.com/profile/15405653497868910661noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-86537569862239815392017-06-06T07:39:25.014-07:002017-06-06T07:39:25.014-07:00The easiest way would be below:
import java.io.*;...The easiest way would be below:<br /><br />import java.io.*;<br /><br />class freqWORD<br />{<br /><br />public static void main(String[] args)throws IOException<br />{<br />int count=0;<br />BufferedReader b=new BufferedReader (new InputStreamReader(System.in));<br />System.out.println("Enter a line");<br />String line=b.readLine();<br />System.out.println("Enter thew word to be searched");<br />String word=b.readLine();<br /><br />String lines[] = line.split(" ");<br /><br />for( String s: lines){<br /> <br /> if (word.equals(s)){<br /> <br /> count++;<br /> }<br />}<br /><br />System.out.println("the word is repeated " +count +" times");<br />System.out.println(line);<br /><br />}<br />}<br /><br /><br />abhishekhttps://www.blogger.com/profile/15405653497868910661noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-53085650466903917222017-06-06T06:26:39.887-07:002017-06-06T06:26:39.887-07:00I would say we should have i<number, instead of...I would say we should have i<number, instead of i<=number , So that the correct number of rows will print abhishekhttps://www.blogger.com/profile/15405653497868910661noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-52324517650405027582017-06-06T03:57:45.932-07:002017-06-06T03:57:45.932-07:00Solution for Question 2:
import java.util.ArrayL...Solution for Question 2: <br /><br />import java.util.ArrayList;<br />import java.util.Scanner;<br /><br />class Actions{<br /><br /> @SuppressWarnings("unused")<br /> private int num;<br /> @SuppressWarnings("unused")<br /> private int d;<br /> @SuppressWarnings("unused")<br /> private char ch;<br /> <br /><br /> public void perform(int num, int d, char ch) {<br /><br /> this.num=num;<br /> this.d=d;<br /> this.ch=ch;<br /> <br /> ArrayList list =new ArrayList();<br /> String [] numberString = Integer.toString(num).split("");<br /> <br /> list.add(Character.toString((char) (ch-1)));<br /> list.add(numberString[1]);<br /> list.add(Integer.toString(d));<br /> list.add(numberString[3]);<br /> list.add(Integer.toString(d));<br /> list.add(Character.toString((char) (ch+1)));<br /> StringBuilder result= new StringBuilder();<br /> for (String s: list)<br /> result.append(s);<br /> <br /> System.out.println("Temp Result : "+result);<br /> }<br /> <br />}<br /><br />public class Tricky {<br /><br /> <br /> public static void main (String[] args ){<br /> <br /> System.out.println("Please enter Number between 1000 to 9999 :");<br /> @SuppressWarnings("resource")<br /> int num = new Scanner(System.in).nextInt();<br /> System.out.println("Please enter Number between 0 to 9 :");<br /> @SuppressWarnings("resource")<br /> int d = new Scanner(System.in).nextInt();<br /> System.out.println("Please enter character :");<br /> @SuppressWarnings("resource")<br /> char ch = new Scanner(System.in).next().charAt(0);<br /> <br /> @SuppressWarnings("rawtypes")<br /> Actions acs = new Actions();<br /> acs.perform(num,d,ch);<br /> <br /> }<br />}<br />abhishekhttps://www.blogger.com/profile/15405653497868910661noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-8270386924128409422017-06-05T07:37:12.356-07:002017-06-05T07:37:12.356-07:00Updated one, as we no need to repeat the biggest ...Updated one, as we no need to repeat the biggest number of stars or number for example 999999999, and also the argument in simpleDrawing(10) has to be 1,3,5,7,9,11or so on not 10 <br />import java.util.ArrayList;<br />import java.util.List;<br /><br />public class pyramidDrawing {<br /><br />public static void main(String[] args) {<br /><br />simpleDrawing(7);<br />arrayDrawing(10);<br /><br />}<br /><br /><br />public static void simpleDrawing(int number) {<br />for(int i = 1; i <= number; i+=2) {<br />for(int j = 1; j <= i; j++) {<br />System.out.print("*");<br />}<br />System.out.println();<br />}<br />for(int v = number-2; v >= 1; v-=2) {<br />for(int q = 1; q <= v; q++) {<br />System.out.print("*");<br />}<br />System.out.println();<br />}<br />}<br /><br /><br />public static void arrayDrawing(int number) {<br />List numere = new ArrayList();<br /><br />for(int numar = 1 ; numar <= number; numar++) {<br />numere.add(numar);<br />}<br /><br />for(int i = 0; i < numere.size(); i++) {<br />if(i % 2 == 0) {<br />for(int j = 0; j <= i; j++) {<br />System.out.print(numere.get(i));<br />}<br />System.out.println();<br />}<br />}<br /><br />for(int v = numere.size()-2; v >= 0; v--) {<br />if(v % 2 != 0) {<br />for(int q = 1; q <= v; q++) {<br />System.out.print(numere.get(v-1));<br />}<br />System.out.println();<br />}<br />}<br />}<br />}<br /><br />abhishekhttps://www.blogger.com/profile/15405653497868910661noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-81221728571552889852017-05-30T05:46:51.271-07:002017-05-30T05:46:51.271-07:00import java.util.Scanner;
public class PracticeDe...import java.util.Scanner;<br /><br />public class PracticeDemo {<br /> <br /> public static void getNumber(int number){<br /> int middle=1;<br /> String start="1",end="1",output;<br /> System.out.println(start);<br /> for(int i=1;i<=number;i++){<br /> middle=middle*2;<br /> output=start+" "+middle+" "+end;<br /> System.out.println(output);<br /> start=start+" "+middle;<br /> end=middle+" "+end;<br /> }<br /> <br /> <br /> }<br /> <br /> <br /> public static void main(String [] args){<br /> Scanner sc=new Scanner(System.in);<br /> System.out.println("Enter the number");<br /> int x=sc.nextInt();<br /> getNumber(x);<br /> sc.close();<br /> }<br /><br /> }<br /><br />output:<br />1<br />1 2 1<br />1 2 4 2 1<br />1 2 4 8 4 2 1<br />1 2 4 8 16 8 4 2 1<br />1 2 4 8 16 32 16 8 4 2 1<br />1 2 4 8 16 32 64 32 16 8 4 2 1<br />1 2 4 8 16 32 64 128 64 32 16 8 4 2 1<br />1 2 4 8 16 32 64 128 256 128 64 32 16 8 4 2 1<br />1 2 4 8 16 32 64 128 256 512 256 128 64 32 16 8 4 2 1<br />1 2 4 8 16 32 64 128 256 512 1024 512 256 128 64 32 16 8 4 2 1<br /><br />Umapathihttps://www.blogger.com/profile/17777708564808987316noreply@blogger.com