Printing Two Strings As Output

Apr 22, 2015

WAP which takes two string as input from the user (a & b).This prog should print two strings as output (a1 & b1).

(a1) should contain all the characters which are present in (a).but not present in (b).
(b1)should contains all the characters which are present in (b).but not present in(a).

View Replies


ADVERTISEMENT

Strings Are Not Printing As They Should?

Jun 12, 2014

Im trying to make a question game, much like a spin off from Trivial Pursuit. In this code, I call classes to get a random number. This number determines what category the question will be from. Coinciding with this number, the "if" statements go and pull the questions and answers from an alternate class. My problem is that when I try and output what should be the question and the 3 answers, its outputs "null" for each String?

This is my first class, which is just the class for the player.

Java Code: /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

[Code].....

View Replies View Related

Not Printing Output When Using While Loops?

May 17, 2015

I am learning while loops but the output I am getting is not what I want? My class:

public class BottlesOnWall {
public static void main (String[] args) {
int x = 99;
while (x > 1) {
System.out.println(x + " bottles on the wall!");

[Code] .....

The output I am getting is this:

99 bottles on the wall!
98 bottles on the wall!
97 bottles on the wall!
96 bottles on the wall!
95 bottles on the wall!

[Code] ....

I want it to stop on "2 bottles on the wall!" and then print "Only 1 bottle left on the wall!". How do I go about doing that? I have tried different variations of the condition (x>1), I have tried (x>5) but it still goes down to 1 bottle?

View Replies View Related

Printing In Output Txt File?

Mar 10, 2014

I have a for cycle in which I have a line for printing in the output file. But the file remains empty.

I inserted ShowMessageDialog in the same cycle in order to see what are the results of the calculations that are supposed to appear in the output file, and I see that the results are fine.

Here is some of the code:

XML Code: BufferedWriter bwLink = new BufferedWriter(new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_LINK));
bwLink.close();
....
....
...
PrintWriter outLink = new PrintWriter(new BufferedWriter(
new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_LINK, true)));
...
...
JOptionPane.showMessageDialog(GuiMain.this, " Link: " +counter + " Normal: " + trafficResult[0] + " ;

[code]....

View Replies View Related

Printing Index Of Output Array

Feb 6, 2014

I want to Display the Index of output Array.

here is the code:
 
import java.util.ArrayList;
import java.util.List;
public class selection {
private static int[] numbers= { 1, 2, 4, 8, 16, 32, 64, 128, 250, 250, 250, 250, 250, 250, 250 };
private static int[] sumsum= new int[numbers.length];
private static int sum= 1759;

[Code] .....

View Replies View Related

Printing A Character - Output Blank

Mar 6, 2014

Why the output is coming out to be blank in the following code.

public class A {
public void call() {
char d = 10 ;
System.out.println(d); // why it is not printing ?
System.out.println((int)d);
}

public static void main(String[] args) {
A a = new A();
a.call();
}
}

View Replies View Related

Arrays / Strings And Related Output Arena

Apr 3, 2014

This is one of the most interesting programmes in java Number-Word..The programme give the alphabet output of a no. inserted between 1 and 10,000

Example :

Input:Enter a word less than 10000

5457

Output:Five Thousand Four Hundred And Fifty Seven

Code:--

import java.util.*;

Java Code:

class num2word
{
public static void main(String args [])
{
num2word ob = new num2word();
ob.check();
}
void check ()

[code]...

View Replies View Related

How To Find Whether Strings Contained In Array Of Strings Constitute A Similar Character Or Not

Aug 25, 2014

I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:

aadafbd
dsfgdfbvc
sdfgyub
fhjgbjhjd

my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).

View Replies View Related

Sorting Lowercase Strings Before Uppercase Strings

Mar 26, 2014

I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.

View Replies View Related

Output For If Else Is Missing Second Output

Feb 15, 2015

my output fails to display me the 2nd output.Here's my code.

import java.util.Scanner;
public class year
{
public static void main (String [] args)
{
Scanner console = new Scanner (System.in);
System.out.print("Enter the choice of book(A-ABC,D-EFG):");
String x = console.next();
System.out.print("Enter the rate (1-3):");
int y= console.nextInt();
System.out.print("Enter number of kids reading:");
int k = console.nextInt();
 
[code]....

When I key '0" for kids, it did not appear the second print out. I don't want the first print out to be the output.

View Replies View Related

How To Compare Strings

Mar 13, 2014

Its supposed to notify the user if they have a palindrome, but keeps returning true even when I type, "hello".

import java.util.Scanner;
public class PalinDrome {
public static void main(String[] args) {
String line;
Scanner input = new Scanner(System.in);
System.out.print("Please enter a word ");

[code]....

View Replies View Related

Reading Only First Name From Strings?

Feb 12, 2014

I know that in c++ in order to read a string like

PHP Code:

. you need to use

getline(cin,string variable)

. In java, I have noticed that using

String name=keyboard.nextLine()

automatically reads the whole line...Suppose I wanted to read the first name only, how would I be able to accomplish that?

View Replies View Related

Extracting The Strings?

Jul 3, 2014

example input (#federer #great #game )->
output : [federer] [great][game], [federer, game],[federer,great], [game,great], [federer, game,great]

View Replies View Related

Top Three Strings In Array

May 18, 2015

I need my code to print out the top three most common IP Addresses in the ArrayList. Right now I have it printing out the top IP Address. I am a little confused as to how to get it to print out three. Every time I change something, It doesn't give me the correct results

My Code:
public class Log_File_Analysis {
private static ArrayList<String> ipAddress = new ArrayList<>();
private static String temp , mostCommon;
static int max = 0;
static int num = 0;

[Code] .....

View Replies View Related

Pass By Value And Strings

Jul 19, 2014

Below is the snippet of code

public static void main(String[] args) throws Exception {
String s = "oldString";
reverse(s);
System.out.println(s); // oldString
}
public static void modifyString(String s) {
s = "newString";
System.out.println(s); // newString
}

I thought the first print statement would print "newString" as String is an object, and when we pass objects between methods, changing state of the object in any method reflects across the methods.

View Replies View Related

How To Use NextLine For Strings

May 12, 2015

I am asking the user a question and already have a correct answer. The answer is a string but is more than one word.

When the user types in the correct answer, it still comes up as wrong but I only have the input.next method.

Quote
Why are rabbits ears long?
United states of america
Incorrect!

View Replies View Related

While Loops And Strings

Jan 3, 2014

So the while loop I am trying to use is:
while( type != "EXIT" ) {
type = input.next();
}

The problem is that typing in EXIT doesn't end the loop like I want it to. I also tried input.nextLine(); but neither of them work. The loop is being used to fill an ArrayList so the number of elements can change based on how many they want. What am I doing wrong, or what alternatives do I have?

Seems I need to use !type.equals("EXIT")

View Replies View Related

Java Won't Allow To Use Strings

Sep 21, 2014

covers switch statements and if/else statements. Java doesn't like the Strings for some reason. My instructor does her strings just like this and it works for her. I can figure out the rest of the program if I can only get around the: "java error35: sSymbol variable might not have been initialized.

import java.util.*;
public class RockPaperScissors
{
public static void main(String[] args) {
//generate outcome
int symbol = (int)(Math.random() * 4);
String sSymbol;

[code]....

View Replies View Related

Operation With Strings

May 6, 2014

I have to write a java programm,where i have given string. Output should be like that:

1. print only once what characters are apearinng in string, and the last index of it

2. print how many characters are in the string

I have to do it only with loops,no special classes

So far:

public static void main( String[] args ) {
String besedilo = "Testiranje";
besedilo = besedilo.toLowerCase();
for (int i=0; i<besedilo.length();i++)

[code]...

View Replies View Related

If Statement With Strings?

May 1, 2015

I am making a simple calculator. I want the user to input either string "add" or "subtract" and then it will take two numbers and either add or subtract them. I cannot get the if statement to work with a string!

import java.util.Scanner;
public class newcalc {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter add or subtract");

String line = input.nextLine();

if input = "add";

View Replies View Related

Strings And Equality

Sep 24, 2014

Output of the program given below:

class A123
{
public static void main(String args[])
{
String s1="hello123";
String s2="hello"+String.valueOf(123);
String s3="hello"+"123";
String s5=new String("hello123");

[Code] ....

why s1 is equal to s3 and not s2

View Replies View Related

JSF :: How To Display List Of Strings

Apr 1, 2014

I have figured out, how to diplay basic datatypes of an entity / object in a dataTable, but I can't find a way to display a List<String>.

I also tried it with ui:repeat, but the space, where it should appear, stays empty. This is my code right now:

Product.java (the entity)

...
@ElementCollection
@CollectionTable(name="NeededRessources", joinColumns=@JoinColumn(name="product_id"))
@Column(name="resource")
private List<String> neededResources;
...

And the page: index.xhtml

<ui:repeat value="#{product.neededResources}" var="t">
#{t}
</ui:repeat>

View Replies View Related

How To Get Average Of Strings Using Array

Apr 21, 2014

I'm trying to calculate the average of grades that a user puts in. Here is my code so far:

public static void main(String[] args) {
Scanner input = new Scanner (System.in); 
System.out.println("Please enter an array of grades seperated bt a comma.");
input.nextLine();
String arrayOfGrades = "100,50,100";
String[] grades = arrayOfGrades.split(",");
 
[Code] .....

I think I'm on the right track, the only big error I'm really getting is the line: sum += grades[i]. It's saying string can not be converted into a double.

View Replies View Related

Comparing Lengths On Strings

Apr 25, 2015

I am making a program i want String length and compare it that it will be null or not but it gives me error.

View Replies View Related

Checking Two Strings In Java?

Feb 10, 2014

I want get a specific document from data set if a given string matches in that document.

If given string is 'what is java' and,

doc1='... what is full form of java ...'

doc2='... is java what ...'

doc3='... what is java ...'

then the output should contains doc1, and doc3.

I'm trying like this.

for(String key_word: key.split("W+")) {
for (String _word : line1.split("W+")) {
if(word.toLowerCase().equals(key_word.toLowerCase())) {
key_final=key_final+" "+key_word;
}
}
}

I'm getting wrong output containing doc1, doc2 and doc3.But I want only the exact match. Here each document is containing some paragraphs.

View Replies View Related

Assigning Random Int To Strings

Jun 16, 2014

while (gamesPlayed<gameQty) {
userChoice = JOptionPane.showInputDialog("Rock, Paper, or Scissors?");
//Determine winner for each game
if (compChoice.equalsIgnoreCase(userChoice));

[Code] ....

It seems to circle through the loop gameQty times, without comparing.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved